#!/bin/bash
currentShellDir=$(cd $(dirname $0); pwd)
installMysql(){

    if  ! command -v docker > /dev/null; then
        . ${currentDir}/dev/installDocker.sh
    fi

    if  ! command -v docker-compose > /dev/null; then
        . ${currentDir}/dev/installDocker.sh
    fi

    /bin/echo -e "输入启动版本号(5.6 | 5.7 | 8.0):"
    read mysqlversion
    if [ ! -d /home/${user}/docker/volumes/mysql${mysqlversion}/logs ]; then
        mkdir -p /home/${user}/docker/volumes/mysql${mysqlversion}/logs
    fi
    if [ ! -d /home/${user}/docker/volumes/mysql${mysqlversion}/data ]; then
        mkdir -p /home/${user}/docker/volumes/mysql${mysqlversion}/data
    fi
    if [ ! -f /home/${user}/docker/volumes/mysql${mysqlversion}/my.cnf ]; then
        cp ${currentDir}/dev/my.cnf /home/${user}/docker/volumes/mysql${mysqlversion}/my.cnf
    fi

    if [ ! -f /home/${user}/docker/docker-compose${mysqlversion}.yml ]; then
        cp ${currentDir}/dev/docker-compose${mysqlversion}.yml /home/${user}/docker/docker-compose${mysqlversion}.yml
    fi
    
    sudo docker-compose -f /home/${user}/docker/docker-compose${mysqlversion}.yml up -d
    
}

installMysql